package valleyOfDemon;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLDecoder;

/**
 * foreword/include请求转发
 */
@WebServlet("/ServletDemo05")
public class ServletDemo05 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //把当前请求发给其他Servlet处理，把路径和2个对象转发过去
        //req.getRequestDispatcher("ServletDemo06").forward(req, resp);
        //include和foreword不同的是，可以在用include方法的当前类中使用响应对象，因为它是现在当前类中处理完后再转发到其它类中
        req.getRequestDispatcher("ServletDemo06").include(req, resp);
        //用了foreword响应对象就不能用了,可以在转发过去的类里用
        //resp.getWriter().write("done!");
        //include
        resp.getWriter().write("include");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
